
import 'package:ayj_flutter_chat_app/pages/chat/chat_page/chat_controller.dart';
import 'package:flutter/material.dart';
import 'package:ayj_flutter_chat_app/common/configs/project_config.dart';


class VoiceButtonsWidget extends StatefulWidget {
  final double buttonW;
  final MeetingStatusType type;
  final ValueChanged<bool> speakOnTap;
  final ValueChanged<bool> voiceOnTap;
  final ValueChanged<bool>? cameraOnTap;
  final ValueChanged<bool>? changeCameraOnTap;
  final GestureTapCallback receiveOnTap;
  final GestureTapCallback cancelOnTap;
  final ControllerType cType;

  const VoiceButtonsWidget({
    super.key,
    required this.buttonW,
    required this.type,
    required this.speakOnTap,
    required this.voiceOnTap,
    this.cameraOnTap,
    this.changeCameraOnTap,
    required this.receiveOnTap,
    required this.cancelOnTap,
    required this.cType,
  });

  @override
  State<VoiceButtonsWidget> createState() => _VoiceButtonsState();
}

/// 换绑手机-校验页面
class _VoiceButtonsState extends State<VoiceButtonsWidget> {
  bool speak = true;
  bool voice = true;

  bool camera = true;
  bool changeCamera = false;


  @override
  Widget build(BuildContext context) {
    if(MeetingStatusType.call == widget.type){
      return Center(
          child:_buildHangUpButton(context),);
    }
    if(MeetingStatusType.waiting == widget.type){
      return Row(
        children: [
          _buildHangUpButton(context),
          SizedBox(width: widget.buttonW*0.4,),
          SizedBox(width: widget.buttonW,),
          SizedBox(width: widget.buttonW*0.4,),
          _buildButton(AppR.chat_voice_meeting_receive,widget.buttonW, widget.receiveOnTap),
        ],
      ).addCenter();
    }
    if(MeetingStatusType.received == widget.type){
      if(widget.cType == ControllerType.meetingVideo){
        double size = widget.buttonW *0.5;
        return Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            _buildButton(voice?AppR.chat_voice_meeting_listent:AppR.chat_voice_meeting_mute,size, (){
              widget.voiceOnTap(!speak);
              setState(() {
                voice = !voice;
              });
            }),

            _buildButton(speak?AppR.chat_voice_meeting_speak:AppR.chat_voice_meeting_mute_speak, size,(){
              widget.speakOnTap(!speak);
              setState(() {
                speak = !speak;
              });
            }),
            _buildHangUpButton(context),
            _buildButton(camera?AppR.chat_video_meeting_video:AppR.chat_video_meeting_mute_video,size, (){
              widget.cameraOnTap!(!camera);
              setState(() {
                camera = !camera;
              });
            }),
            _buildButton(AppR.chat_video_meeting_change_camera, size,(){
              widget.changeCameraOnTap!(!changeCamera);
              changeCamera = !changeCamera;
            }),

          ],
        ).addCenter();
      }

      return Row(
        children: [
          _buildButton(voice?AppR.chat_voice_meeting_listent:AppR.chat_voice_meeting_mute,widget.buttonW, (){
            widget.voiceOnTap(!speak);
            setState(() {
              voice = !voice;
            });
          }),
          SizedBox(width: widget.buttonW*0.4,),
          _buildHangUpButton(context),
          SizedBox(width: widget.buttonW*0.4,),
          _buildButton(speak?AppR.chat_voice_meeting_speak:AppR.chat_voice_meeting_mute_speak,widget.buttonW, (){
            widget.speakOnTap(!speak);
            setState(() {
              speak = !speak;
            });
          }),
        ],
      ).addCenter();
    }

    return const SizedBox();

  }

  Widget _buildHangUpButton(BuildContext context){
    return _buildButton(AppR.chat_voice_meeting_hang_up,widget.buttonW, (){
      widget.cancelOnTap();
    });
  }

  Widget _buildButton(String image,double size,GestureTapCallback onTap){
    return GestureDetector(
      onTap: onTap,
      child:AppImage.assets(image,
        width: size,
        height:size ,
      ),
    );
  }

}